package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.dao.provider.RoleRelationProvider;
import com.jinmdz.fmis.dao.admin.model.rolerelation.RoleMenuButtonListItem;
import com.jinmdz.fmis.dao.admin.model.rolerelation.RoleMenuListItem;
import com.jinmdz.fmis.dao.admin.model.rolerelation.RoleUserListItem;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

/**
 * 角色用户关联Dao
 *
 * @author LiCongLu
 * @date 2020-03-19 9:55
 */
public interface RoleRelationDao {

    /**
     * 按照角色主键查询角色关联帐号用户列表
     *
     * @param roleId 角色主键
     * @return
     * @author LiCongLu
     * @date 2020-03-19 10:05
     */
    @SelectProvider(type = RoleRelationProvider.class, method = "listRoleUserByRoleId")
    ArrayList<RoleUserListItem> listRoleUserByRoleId(@Param("roleId") Integer roleId);

    /**
     * 按照关联主键查询关联用户列表数据
     *
     * @param id 关联主键
     * @return
     * @author LiCongLu
     * @date 2020-03-19 11:04
     */
    @SelectProvider(type = RoleRelationProvider.class, method = "getRoleUserById")
    RoleUserListItem getRoleUserById(@Param("id") Integer id);

    /**
     * 按照角色主键与用户主键验证是否关联了
     *
     * @param roleId 当前角色主键
     * @param userId 用户主键
     * @return
     * @author LiCongLu
     * @date 2020-03-19 10:52
     */
    @Select(" select id from role_user_relation where business_system_role_id = #{roleId} and system_user_id = #{userId} and deleted = 0 limit 1 ")
    @ResultType(Integer.class)
    Integer getRoleRelationIdByUserId(@Param("roleId") Integer roleId, @Param("userId") Integer userId);

    /**
     * 按照系统主键及角色主键查询菜单列表
     *
     * @param systemId 系统主键
     * @param roleId   角色主键
     * @return
     * @author LiCongLu
     * @date 2020-03-19 12:57
     */
    @SelectProvider(type = RoleRelationProvider.class, method = "listRoleMenuListBySystemId")
    ArrayList<RoleMenuListItem> listRoleMenuListBySystemId(@Param("systemId") Integer systemId, @Param("roleId") Integer roleId);

    /**
     * 按照系统主键及角色主键查询菜单按钮列表
     *
     * @param systemId 系统主键
     * @param roleId   角色主键
     * @return
     * @author LiCongLu
     * @date 2020-03-19 12:57
     */
    @SelectProvider(type = RoleRelationProvider.class, method = "listRoleMenuButtonListBySystemId")
    ArrayList<RoleMenuButtonListItem> listRoleMenuButtonListBySystemId(@Param("systemId") Integer systemId, @Param("roleId") Integer roleId);

    /**
     * 清除授权给角色的菜单关联
     *
     * @param roleId         角色主键
     * @param modifiedUserId 修改用户外键
     * @return
     * @author generator
     * @date 2020-03-19 13:44
     */
    @Update(" update role_menu_relation set deleted = 1,modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where business_system_role_id = #{roleId} and deleted = 0 ")
    void deletedForRoleMenuRelation(@Param("roleId") Integer roleId, @Param("modifiedUserId") Integer modifiedUserId);

    /**
     * 清除授权给角色的菜单按钮关联
     *
     * @param roleId         角色主键
     * @param modifiedUserId 修改用户外键
     * @return
     * @author generator
     * @date 2020-03-19 13:44
     */
    @Update(" update role_menu_button_relation set deleted = 1,modified_user_id = #{modifiedUserId},version = unix_timestamp(now()) where business_system_role_id = #{roleId} and deleted = 0 ")
    void deletedForRoleMenuButtonRelation(@Param("roleId") Integer roleId, @Param("modifiedUserId") Integer modifiedUserId);
}